package cn.darkhorse.workflow.service.impl;

import cn.darkhorse.api.IActivitiService;
import cn.darkhorse.exception.ServiceException;
import cn.darkhorse.workflow.auto.entity.BpmnAgent;
import cn.darkhorse.workflow.auto.service.IBpmnAgentService;
import cn.darkhorse.workflow.service.IBpmnAgentExtService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @description:
 * @author: mr.wang
 * @time: 2024/1/4 9:05
 */
@Service
public class BpmnAgentExtServiceImpl  implements IBpmnAgentExtService{
	
	@Resource
	private IBpmnAgentService iBpmnAgentService;
	
	@Resource
	private IActivitiService iActivitiService;
	
	@Override
	public void add(Long businessId, Long businessType, String businessName) {
		BpmnAgent bpmnAgent = new BpmnAgent();
		bpmnAgent.setBusinessId(businessId);
		bpmnAgent.setBusinessName(businessName);
		bpmnAgent.setBusinessType(businessType);
		iBpmnAgentService.saveOrUpdate(bpmnAgent);
	}
	
	
	@Override
	public void delete(Long businessId, Long businessType, String processInstanceId) {
		Boolean aBoolean = iActivitiService.processIsOverById(processInstanceId);
		if (aBoolean){
			LambdaQueryWrapper<BpmnAgent> bpmnAgentWrapper = new LambdaQueryWrapper<BpmnAgent>()
					.eq(BpmnAgent::getBusinessId,businessId)
					.eq(BpmnAgent::getBusinessType,businessType);
			boolean remove = iBpmnAgentService.remove(bpmnAgentWrapper);
			if (!remove){
				throw new ServiceException("删除待办事项失败!");
			}
		}
	}
	
	
	
	
	
	
}
